package demo1;

import java.util.Arrays;
import java.util.Comparator;

class Student {
    private String name;
    private double chinese;
    private double english;
    private double math;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getChinese() {
        return chinese;
    }

    public void setChinese(double chinese) {
        this.chinese = chinese;
    }

    public double getEnglish() {
        return english;
    }

    public void setEnglish(double english) {
        this.english = english;
    }

    public double getMath() {
        return math;
    }

    public void setMath(double math) {
        this.math = math;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    //总分
    private double score;
    public Student(String name ,double chinese, double english, double math) {
        this.name = name;
        this.chinese = chinese;
        this.english = english;
        this.math = math;
        this.score = chinese + english + math;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", english=" + english +
                '}';
    }
}

//按照英文成绩从小到大排序
class EnglishComparator implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return (int)(o1.getEnglish() - o2.getEnglish());
    }
}
//按照名字排序（按英语字符表顺序排）
class NameComparator implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return o1.getName().compareTo(o2.getName());
    }
}
public class test2 {
    public static void main(String[] args) {
        Student[] students = {
                new Student("zhangsan",52.0,68.6,98.2),
                new Student("lisi",89.5,36.5,82.5),
                new Student("wangwu",95.0,75.8,56.2)
        };
        Arrays.sort(students, new EnglishComparator());
        System.out.println(Arrays.toString(students));
    }
}
